﻿using Mall.Infrastructure.Container;
using Mall.Infrastructure.Model;
using Sx.Mall.WebContract;
using Sx.Mall.WebContract.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sx.Mall.Web.Controllers
{
    public class ManagerUserController : Controller
    {
        private static InterfaceContainer app = AppDomain.CurrentDomain.GetContainer();

        private IMallManagerService service;

        public ManagerUserController()
        {
            service = app.GetSerivce<IMallManagerService>();

        }



        /// <summary>
        /// 查找系统人员
        /// </summary>
        /// <param name="username"></param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        public JsonResult GetList(string s_userName, int page, int rows)
        {
            MallManagerDto dto = new MallManagerDto();
            dto.Page = new Page();
            dto.Page.PageSize = rows;
            dto.Page.CurrentPage = page;
            dto.UserName = s_userName;
            var result = service.GetList(dto);
            return Json(result);
        }

        /// <summary>
        /// 添加系统人员
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddUser(MallManagerDto dto)
        {
            dto.Status = 1;
            dto.ErrorCount = 0;
            dto.Islocked = false;
            var result = service.Add(dto);
            return Json(result);
        }

        /// <summary>
        /// 修改人员
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Update(MallManagerDto dto, int id)
        {
            dto.UserID = id;
            var result = service.Update(dto);
            return Json(result);
        }


        /// <summary>
        ///批量删除系统人员
        /// </summary>
        /// <param name="ids">人员ID集合</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult DeleteUser(string ids)
        {
            List<int> list = ids.Split(',').Select(m => Convert.ToInt32(m)).ToList();
            var result = service.DeleteUser(list);
            return Json(result);
        }

    }
}
